<template>
    <div class="container">
        <Swiper class="swiper" :autoplay="swiper_option.autoplay" :loop="swiper_option.loop" :speed="swiper_option.speed"
            :pagination="swiper_option.pagination" :navigation="swiper_option.Navigation" :slides-per-view="1">
            <swiper-slide v-for="(item, index) in bannerData" :key="index">
                <router-link :to="{ name: 'playListDetail', query: { id: item.targetId } }">
                    <img :src="item.imageUrl" alt="">
                </router-link>
            </swiper-slide>
        </Swiper>
        <div class="recommend-list">
            <div class="recommend-list-left">
                <div class="hotRecommendation">
                    <div class="list-title">
                        <div class="title-left">
                            <a href="">热门推荐</a>
                            <div class="title-tab">
                                <a href="" :title="item.name" v-for="(item, index) in hotTitleList" :key="index">{{
                                    item.name }}</a>
                            </div>
                        </div>
                        <div class="title-right">
                            <a href="">更多</a>
                            <i>&nbsp;</i>
                        </div>
                    </div>
                    <div class="hot-list-left-content">
                        <playListItems v-for="(item, index) in hotList" :title="item.name" :src="item.picUrl"
                            :playCount="item.playCount" :id="item.id" :key="index"></playListItems>
                    </div>
                </div>
                <div class="newDisc">
                    <div class="list-title" style="margin-top: 35px;">
                        <div class="title-left">
                            <a href="">新碟上架</a>
                        </div>
                        <div class="title-right">
                            <a href="">更多</a>
                            <i>&nbsp;</i>
                        </div>
                    </div>
                    <div class="newDisc-content">
                        <Swiper :space-between="15" :slides-per-view="5" :navigation="swiper2_option.Navigation"
                            :loop="swiper2_option.loop" :speed="swiper2_option.speed">
                            <swiper-slide v-for="(item, index) in newDiscData" :key="index">
                                <newDiscItems :src="item.picUrl" :name="item.name" :author="item.artist.name" :id="item.id">
                                </newDiscItems>
                            </swiper-slide>
                        </Swiper>
                    </div>
                </div>
                <div class="topList">
                    <div class="list-title" style="margin-top: 35px;">
                        <div class="title-left">
                            <a href="">榜单</a>
                        </div>
                        <div class="title-right">
                            <a href="">更多</a>
                            <i>&nbsp;</i>
                        </div>
                    </div>
                    <div class="topList-content">
                        <div class="topListItem" v-for="(item, index) in topListDetailData" :key="index">
                            <div class="topListItem-top">
                                <div class="img">
                                    <img :src="item.coverImgUrl" alt="">
                                    <a class="imgback" href=""></a>
                                </div>
                                <div class="topListItem-title">
                                    <a href="">{{ item.name }}</a>
                                    <div class="topListItem-title-button">
                                        <a class="playIcon" href="javascript:;"></a>
                                        <a class="saveIcon" href="javascript:;"></a>
                                    </div>
                                </div>
                            </div>
                            <div class="topListItem-list">
                                <ul>
                                    <li v-for="(item1, index1) in item.tracks.slice(0, 10)">
                                        <span>{{ index1 + 1 }}</span>
                                        <a href="">{{ item1.name }}</a>
                                        <div class="li-button">
                                            <div class="playIcon" @click="getSingId(item1?.id)"></div>
                                            <div class="addIcon"></div>
                                            <div class="saveIcon"></div>
                                        </div>
                                    </li>
                                </ul>
                                <div class="more">
                                    <a href="">查看全部></a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="recommend-list-right">
                <div class="recommend-list-right-login-false"
                    v-if="!loginUseStore.loginStatus && loginUseStore.cookie == null">
                    <p>登录网易云音乐，可以享受无限收藏的乐趣，并且无限同步到手机</p>
                    <a href="javascript:;" @click="loginUseStore.flag = true">用户登录</a>
                </div>
                <div class="recommend-list-right-login-true" v-else>
                    <div class="login-top">
                        <div class="login-top-left">
                            <a href="">
                                <img :src="loginUseStore.profile?.avatarUrl" alt="">
                            </a>
                        </div>
                        <div class="login-top-right">
                            <h4>
                                <a href="">{{ loginUseStore?.profile?.nickname }}</a>
                                <span></span>
                            </h4>
                            <p>
                                <a href="">0<i></i></a>
                            </p>
                            <div class="btnwrap">
                                <a href="">
                                    <i>已签到</i>
                                </a>
                            </div>
                        </div>
                    </div>
                    <ul class="login-bottom">
                        <li>
                            <a href="">
                                <strong>{{ loginUseStore.userEvent?.size }}</strong>
                                <span>动态</span>
                            </a>
                        </li>
                        <li>
                            <a href="">
                                <strong>{{ loginUseStore.userFollow.length }}</strong>
                                <span>关注</span>
                            </a>
                        </li>
                        <li>
                            <a href="">
                                <strong>{{ loginUseStore.userFollowsed?.size }}</strong>
                                <span>粉丝</span>
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="recommend-list-right-singer">
                    <div class="singer-title">
                        <span>入驻歌手</span>
                        <a href="">查看全部 ></a>
                    </div>
                    <ul class="singer-list">
                        <li v-for="(item, index) in singerData" :key="index">
                            <a href="">
                                <div class="singer-img">
                                    <img :src="item.img1v1Url" alt="">
                                </div>
                                <div class="singer-message">
                                    <div class="singer-name">
                                        <span>{{ item.name }}</span>
                                    </div>
                                    <div class="singer-synopsis">
                                        <span>{{ item.alias[0], item.alias[1] }}</span>
                                    </div>
                                </div>
                            </a>
                        </li>
                    </ul>
                    <div class="singer-button">
                        <a href="https://music.163.com/st/musician">
                            <i>申请成为网易音乐人</i>
                        </a>
                    </div>
                </div>
                <div class="recommend-list-right-anchor">
                    <div class="anchor-title">
                        热门主播
                    </div>
                    <ul class="anchor-list">
                        <li v-for="(item, index) in anchorData" :key="index">
                            <div class="li-left">
                                <a href="">
                                    <img :src="item.avatarUrl" alt="">
                                </a>
                            </div>
                            <div class="li-right">
                                <p>
                                    <a href="">{{ item.nickName }}</a>
                                </p>
                                <p>{{ item.mainAuthDesc }}</p>
                            </div>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Swiper, SwiperSlide } from 'swiper/vue'
import "swiper/swiper.min.css";
import 'swiper/swiper-bundle.css'
import { swiper2_option } from '@/api/discoverMusic/recommend/type'
import SwiperCore, { Autoplay, Pagination, Navigation } from 'swiper'
import { RequestData } from '@/api/discoverMusic/recommend/type'
import playListItems from '@/components/playListItems/index.vue'
import newDiscItems from '@/components/newDiscItems/index.vue'
import playerStore from '@/store/modules/player';
import loginStore from '@/store/modules/login';
import { reqBanner, reqHotCategory, reqHotList, reqNewDisc, reqTopList, reqTopListDetail, reqSingerList, reqAnchorList } from '@/api/discoverMusic/recommend';
SwiperCore.use([Autoplay, Pagination, Navigation])
let swiper_option = ref({
    autoplay: {
        delay: 3000,
        disableOnInteraction: false
    },
    loop: true,
    speed: 1000,
    pagination: {
        clickable: true
    },
    Navigation: {
        nextElRef: '.swiper-button-next',
        prevElRef: '.swiper-button-prev'
    }
})
let swiper2_option: swiper2_option = ref({
    loop: true,
    speed: 500,
    Navigation: {
        nextElRef: '.swiper-button-next',
        prevElRef: '.swiper-button-prev'
    }
})
let loginUseStore = loginStore()
let bannerData = ref<any>([])
let hotTitleList = ref<any>([])
let hotList = ref<any>([])
let newDiscData = ref<any>([])
let topListData = ref<any>([])
let topListDetailData = ref<any>([])
let singerData = ref<any>([])
let anchorData = ref<any>([])
let playerUseStore = playerStore()
onMounted(() => {
    getBanner()
    getHotCategory()
    getHotList()
    getNewDiscList()
    getTopList()
    getSingerList()
    getAnchorList()
})
const getBanner = async () => {
    let result: RequestData = await reqBanner()
    if (result.code == 200) {
        bannerData.value = result.banners
    }
}
const getHotCategory = async () => {
    let result = await reqHotCategory()
    if (result.code == 200) {
        hotTitleList.value = result.tags.slice(0, 5)
    }
}
const getHotList = async () => {
    let result = await reqHotList(8)
    if (result.code == 200) {
        hotList.value = result.result
    }
}

const getNewDiscList = async () => {
    let result = await reqNewDisc(10)
    if (result.code == 200) {
        newDiscData.value = result.albums
    }
}

const getTopList = async () => {
    let result = await reqTopList()
    if (result.code == 200) {
        topListData.value = result.list.slice(0, 3)
    }
    for (let i = 0; i < topListData.value.length; i++) {
        let listData = await reqTopListDetail(topListData.value[i].id)
        if (listData.code == 200) {
            topListDetailData.value.push(listData.playlist)
        }
    }
}
const getSingerList = async () => {
    let result = await reqSingerList(5)
    if (result.code == 200) {
        singerData.value = result.artists
    }
}

const getAnchorList = async () => {
    let result = await reqAnchorList(5)
    if (result.code == 200) {
        anchorData.value = result.data.list
    }
}

const getSingId = async (id: any) => {
    await playerUseStore.getsingMessage(id)
}

</script>

<style lang="less">
.swiper {
    height: 400px;
    width: 100%;

    .swiper-slide {
        a {
            display: block;
            width: 100%;
            height: 100%;

            img {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        }
    }

    .swiper-container-horizontal>.swiper-pagination-bullets .swiper-pagination-bullet {
        margin: 0 10px;
    }

    .swiper-button-prev:after,
    .swiper-container-rtl .swiper-button-next:after,
    .swiper-button-next:after,
    .swiper-container-rtl .swiper-button-prev:after {
        color: #E9E5E4;
        padding: 10px;
    }

    .swiper-button-prev:hover::after {
        background-color: rgba(0, 0, 0, .4);
    }

    .swiper-button-next:hover::after {
        background-color: rgba(0, 0, 0, .4);
    }
}

.swiper-pagination {
    .swiper-pagination-bullet {
        width: 6px;
        height: 6px;
        background-color: rgba(255, 255, 255, .7);
        opacity: 1;
    }

    .swiper-pagination-bullet-active {
        background-color: #C40C0C;
    }
}

.recommend-list {
    display: flex;
    border-width: 0 1px;
    width: 100%;

    .list-title {
        height: 33px;
        padding: 0 10px 0 34px;
        background: url(../../../assets/images/index.png) no-repeat;
        background-position: -225px -156px;
        border-bottom: 2px solid #C10D0C;
        display: flex;
        justify-content: space-between;

        .title-left {
            display: flex;

            >a {
                font-size: 20px;
                font-weight: normal;
                line-height: 28px;
                color: #333;
            }

            .title-tab {
                margin: 5px 0 0 20px;
                height: 16px;

                a {
                    font-size: 12px;
                    color: #666;
                    padding: 0 10px;
                    border-right: 1px solid #ccc;

                    &:hover {
                        text-decoration: underline;
                    }

                    &:last-child {
                        border: none;
                    }
                }
            }
        }

        .title-right {
            padding-top: 5px;

            a {
                color: #666;
                font-size: 12px;
            }

            i {
                display: inline-block;
                width: 12px;
                height: 12px;
                margin-left: 4px;
                vertical-align: middle;
                background: url(../../../assets/images/index.png) no-repeat;
                background-position: 0 -240px;
            }
        }

    }

    .recommend-list-left {
        width: 729px;
        padding: 20px 20px 40px;
        box-sizing: border-box;
        border-right: 1px solid #d3d3d3;
        .hotRecommendation {
            .hot-list-left-content {
                display: flex;
                flex-wrap: wrap;
                margin: 20px 0 0 0;

                .playListItems {
                    margin-right: 42px;
                    margin-bottom: 30px;

                    &:nth-child(4n) {
                        margin-right: 0;
                    }
                }
            }
        }

        .newDisc {
            .newDisc-content {
                position: relative;
                zoom: 1;
                height: 186px;
                margin: 20px 0 37px;
                border: 1px solid #d3d3d3;
                background: #f5f5f5;
                padding: 28px 20px 0 20px;
                box-sizing: border-box;

                .swiper-container {
                    position: unset;

                    .swiper-button-prev {
                        position: absolute;
                        top: 90px;
                        width: 17px;
                        height: 17px;
                        left: 4px;
                        display: block;
                        background: url(../../../assets/images/index.png);
                        background-position: -260px -75px;

                        &::after {
                            content: '';
                        }
                    }

                    .swiper-button-next {
                        position: absolute;
                        top: 90px;
                        width: 17px;
                        height: 17px;
                        right: 4px;
                        display: block;
                        background: url(../../../assets/images/index.png);
                        background-position: -300px -75px;

                        &::after {
                            content: '';
                        }
                    }
                }
            }
        }

        .topList {
            .topList-content {
                height: 472px;
                margin-top: 20px;
                background: url(../../../assets/images/index_bill.png);

                .topListItem {
                    float: left;
                    width: 229px;

                    .topListItem-top {
                        height: 100px;
                        padding: 20px 0 0 21px;
                        box-sizing: border-box;
                        margin-bottom: 20px;

                        .img {
                            float: left;
                            width: 80px;
                            height: 80px;
                            position: relative;

                            img {
                                width: 100%;
                                height: 100%;
                            }

                            .imgback {
                                position: absolute;
                                top: 0;
                                left: 0;
                                width: 100%;
                                height: 100%;
                                background: url(../../../assets/images/coverall.png);
                                background-position: -145px -57px;
                            }
                        }

                        .topListItem-title {
                            float: left;
                            width: 116px;
                            margin: 6px 0 0 10px;

                            >a {
                                color: #333;
                                font-size: 14px;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                                word-wrap: normal;
                                font-weight: 700;
                            }

                            .topListItem-title-button {
                                margin-top: 10px;

                                .playIcon {
                                    display: block;
                                    float: left;
                                    width: 22px;
                                    height: 22px;
                                    margin-right: 10px;
                                    text-indent: -9999px;
                                    background: url(../../../assets/images/index.png);
                                    background-position: -267px -205px;

                                    &:hover {
                                        background-position: -267px -235px;
                                    }
                                }

                                .saveIcon {
                                    display: block;
                                    float: left;
                                    width: 22px;
                                    height: 22px;
                                    margin-right: 10px;
                                    text-indent: -9999px;
                                    background: url(../../../assets/images/index.png);
                                    background-position: -300px -205px;

                                    &:hover {
                                        background-position: -300px -235px;
                                    }
                                }
                            }
                        }

                    }

                    .topListItem-list {
                        ul {
                            height: 319px;
                            margin-left: 50px;
                            line-height: 32px;

                            li {
                                height: 32px;

                                &:hover {
                                    a {
                                        display: block;
                                        width: 96px;
                                        text-decoration: underline;
                                    }

                                    .li-button {
                                        display: block;
                                    }
                                }

                                >span {
                                    float: left;
                                    position: relative;
                                    width: 35px;
                                    height: 32px;
                                    margin-left: -35px;
                                    text-align: center;
                                    color: #666;
                                    font-size: 16px;
                                }

                                a {
                                    float: left;
                                    display: block;
                                    width: 170px;
                                    height: 32px;
                                    color: #000;
                                    font-size: 12px;
                                    overflow: hidden;
                                    text-overflow: ellipsis;
                                    white-space: nowrap;
                                }

                                .li-button {
                                    float: right;
                                    width: 82px;
                                    margin-top: 7px;
                                    display: none;

                                    .playIcon {
                                        float: left;
                                        width: 17px;
                                        height: 17px;
                                        margin-right: 10px;
                                        background: url(../../../assets/images/index.png);
                                        background-position: -267px -268px;
                                        cursor: pointer;

                                        &:hover {
                                            background-position: -267px -288px;
                                        }
                                    }

                                    .addIcon {
                                        float: left;
                                        width: 17px;
                                        height: 17px;
                                        margin: 2px 6px 0 0;
                                        background: url(../../../assets/images/icon.png);
                                        background-position: 0 -700px;
                                        cursor: pointer;

                                        &:hover {
                                            background-position: -22px -700px;
                                        }
                                    }

                                    .saveIcon {
                                        float: left;
                                        width: 17px;
                                        height: 17px;
                                        margin-right: 10px;
                                        background: url(../../../assets/images/index.png);
                                        background-position: -297px -268px;
                                        cursor: pointer;

                                        &:hover {
                                            background-position: -297px -288px;
                                        }
                                    }
                                }
                            }
                        }

                        .more {
                            height: 32px;
                            margin-right: 25px;
                            text-align: right;
                            line-height: 32px;

                            a {
                                color: #000;
                                font-size: 12px;
                            }
                        }
                    }
                }
            }
        }
    }

    .recommend-list-right {
        width: calc(100% - 729px);

        .recommend-list-right-login-false {
            height: 126px;
            background: url(../../../assets/images/index.png) no-repeat;
            background-position: 0 0;

            p {
                width: 205px;
                margin: 0 auto;
                padding: 16px 0;
                line-height: 22px;
                font-size: 12px;
            }

            a {
                display: block;
                margin: 0 auto;
                width: 100px;
                height: 31px;
                line-height: 31px;
                text-align: center;
                color: #fff;
                text-shadow: 0 1px 0 #8a060b;
                background: url(../../../assets/images/index.png);
                background-position: 0 -195px;
                font-size: 12px;
            }
        }

        .recommend-list-right-login-true {
            height: 165px;
            box-sizing: content-box;
            padding-top: 20px;
            background-image: url(../../../assets/images/index.png);
            background-position: 0 -270px;

            .login-top {
                display: flex;

                .login-top-left {
                    width: 80px;
                    height: 80px;
                    margin-left: 20px;
                    background: #fff;
                    border: 1px solid #dadada;
                    padding: 2px;
                    box-sizing: content-box;

                    a {
                        display: block;
                        width: 100%;
                        height: 100%;

                        img {
                            width: 100%;
                            height: 100%;
                        }
                    }
                }

                .login-top-right {
                    width: 115px;
                    margin-left: 18px;
                    padding-top: 3px;

                    h4 {
                        height: 20px;
                        display: flex;
                        align-items: end;

                        a {
                            display: block;
                            max-width: 60px;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                            color: #333;
                            font-weight: 700;
                            font-size: 14px;
                        }

                        span {
                            width: 45px;
                            height: 16px;
                            background-size: auto 15px;
                            background-repeat: no-repeat;
                            background-position: center;
                            margin-left: 5px;
                            display: flex;
                            flex-direction: column;
                            justify-content: center;
                        }
                    }

                    p {
                        width: 100px;
                        margin-top: 5px;

                        a {
                            display: flex;
                            height: 17px;
                            align-items: center;
                            width: 40.4px;
                            box-sizing: border-box;
                            overflow: hidden;
                            padding-left: 25px;
                            color: #999;
                            font-weight: bold;
                            font-style: italic;
                            font-size: 12px;
                            background-image: url(../../../assets/images/icon2.png);
                            background-position: -130px -64px;
                            vertical-align: middle;

                            &:hover {
                                background-position: -130px -84px;
                                color: #777;
                            }

                            i {
                                background-image: url(../../../assets/images/icon2.png);
                                background-position: -192px -64px;
                                display: inline-block;
                                width: 8px;
                                height: 17px;
                                background-position: -192px -64px;
                            }
                        }
                    }

                    .btnwrap {
                        margin-top: 15px;

                        a {
                            color: #bebebe;
                            padding: 0 5px 0 0;
                            display: inline-block;
                            height: 31px;
                            line-height: 31px;
                            overflow: hidden;
                            vertical-align: top;
                            text-align: center;
                            background-image: url(../../../assets/images/button2.png);
                            background-position: right -346px;
                            font-size: 12px;

                            i {
                                color: #bebebe;
                                background-position: 0 -305px;
                                padding: 0 15px 0 20px;
                                pointer-events: none;
                                height: 31px;
                                line-height: 31px;
                                overflow: hidden;
                                display: inline-block;
                                vertical-align: top;
                                text-align: center;
                                background-image: url(../../../assets/images/button2.png);
                                background-position: 0 -305px;
                            }
                        }
                    }
                }
            }

            .login-bottom {
                position: relative;
                display: flex;
                justify-content: space-between;
                margin-top: 22px;
                padding: 0 25px;

                li {
                    height: 40px;
                    position: relative;

                    &::after {
                        content: '';
                        display: block;
                        height: 40px;
                        background-color: #e4e4e4;
                        width: 1px;
                        position: absolute;
                        right: -26px;
                        top: 0;
                    }

                    &:last-child {
                        &::after {
                            display: none;
                        }
                    }

                    a {
                        display: block;
                        color: #666;
                        font-size: 12px;

                        strong {
                            display: block;
                            font-size: 20px;
                            font-weight: normal;
                            white-space: nowrap;
                            margin-bottom: 5px;
                        }

                        span {
                            margin-left: 2px;
                        }
                    }
                }
            }
        }

        .recommend-list-right-singer {
            margin-top: 15px;
            font-size: 12px;

            .singer-title {
                position: relative;
                height: 23px;
                margin: 0 20px;
                border-bottom: 1px solid #ccc;
                color: #333;

                span {
                    color: #333;
                    float: left;
                    font-weight: 700;
                }

                a {
                    float: right;
                    color: #666;
                }
            }

            .singer-list {
                margin: 6px 0 14px 20px;

                li {
                    width: 210px;
                    height: 62px;
                    background: #fafafa;
                    margin-top: 14px;

                    a {
                        display: block;
                        width: 100%;
                        height: 100%;

                        .singer-img {
                            width: 62px;
                            height: 62px;
                            float: left;

                            img {
                                width: 100%;
                                height: 100%;
                            }
                        }

                        .singer-message {
                            width: 133px;
                            height: 60px;
                            float: left;
                            padding-left: 14px;
                            border: 1px solid #e9e9e9;
                            border-left: none;
                            box-sizing: content-box;
                            font-size: 12px;
                            color: #666;

                            .singer-name {
                                font-size: 12px;
                                font-weight: 700;
                                margin-top: 8px;
                                height: 22px;
                                color: #333;
                                font-size: 14px;
                            }

                            .singer-synopsis {
                                margin-top: 8px;
                                width: 90%;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                            }
                        }
                    }
                }
            }

            .singer-button {
                a {
                    display: block;
                    border-radius: 4px;
                    font-size: 12px;
                    color: #333;
                    margin-left: 20px;
                    width: 210px;
                    height: 31px;
                    line-height: 29px;
                    text-align: center;
                    font-weight: bold;
                    border-radius: 5px;
                    border: 1px solid #c3c3c3;
                    background-color: #F9F9F9;
                    box-sizing: border-box;
                }
            }
        }

        .recommend-list-right-anchor {
            margin-top: 30px;

            .anchor-title {
                position: relative;
                height: 23px;
                margin: 0 20px;
                border-bottom: 1px solid #ccc;
                color: #333;
                font-size: 12px;
                font-weight: 700;
            }

            .anchor-list {
                margin: 20px 0 0 20px;

                li {
                    width: 210px;
                    height: 50px;
                    display: flex;

                    .li-left {
                        width: 40px;
                        margin-right: 10px;

                        a {
                            display: block;
                            width: 100%;
                            height: 100%;

                            img {
                                width: 40px;
                                height: 40px;
                                box-shadow: 0 0 1px #333333 inset;
                            }
                        }
                    }

                    .li-right {
                        width: 160px;
                        line-height: 21px;
                        font-size: 12px;

                        p:nth-child(1) {
                            a {
                                color: #000;
                            }
                        }

                        p:nth-child(2) {
                            color: #666;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            white-space: nowrap;
                        }
                    }
                }
            }
        }
    }
}</style>